#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/9/6 9:44
# @Updatetime：9:44
# @Author：Test008
# @File：1-美日印疫情图开发
# @Description：

import json
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LabelOpts, ToolboxOpts, VisualMapOpts, LegendOpts

# 数据准备
# 1》处理数据
# 2》去掉多余的json开头和结尾部分，转为字典格式
# 3》获取 trend key值，获取“日期”数据作为x轴，获取“确诊”数据作为y轴
# 4》生成图表，添加标题,设置全局选项

with open('../../../static/doc/yiqing_data/美国.txt', 'r', encoding='utf-8') as f_us:
    us_content = f_us.read()
us_content = us_content.replace('jsonp_1629344292311_69436(', '')
us_content = us_content[:-2]
us_content = json.loads(us_content)

with open('../../../static/doc/yiqing_data/印度.txt', 'r', encoding='utf-8') as f_in:
    in_content = f_in.read()
in_content = in_content.replace('jsonp_1629350745930_63180(', '')
in_content = in_content[:-2]
in_content = json.loads(in_content)

with open('../../../static/doc/yiqing_data/日本.txt', 'r', encoding='utf-8') as f_jp:
    jp_content = f_jp.read()
jp_content = jp_content.replace('jsonp_1629350871167_29498(', '')
jp_content = jp_content[:-2]
jp_content = json.loads(jp_content)

# x轴为日期，y轴为确诊人数，至于人数，死亡人数，确诊人数
us_x_data = us_content['data'][0]['trend']['updateDate'][:314]
us_qz_y_data = us_content['data'][0]['trend']['list'][0]['data'][:314]
# us_zy_y_data = us_content['data'][0]['trend']['list'][1]['data'][:314]
# us_sw_y_data = us_content['data'][0]['trend']['list'][2]['data'][:314]
# us_xz_y_data = us_content['data'][0]['trend']['list'][3]['data'][:314]

in_x_data = in_content['data'][0]['trend']['updateDate'][:314]
in_qz_y_data = in_content['data'][0]['trend']['list'][0]['data'][:314]
# in_zy_y_data = in_content['data'][0]['trend']['list'][1]['data'][:314]
# in_sw_y_data = in_content['data'][0]['trend']['list'][2]['data'][:314]
# in_xz_y_data = in_content['data'][0]['trend']['list'][3]['data'][:314]

jp_qz_y_data = jp_content['data'][0]['trend']['list'][0]['data'][:314]

line = Line()
line.add_xaxis(us_x_data)
line.add_yaxis('美国确诊人数', us_qz_y_data, label_opts=LabelOpts(is_show=False))
line.add_yaxis('印度确诊人数', in_qz_y_data, label_opts=LabelOpts(is_show=False))
line.add_yaxis('日本确诊人数', jp_qz_y_data, label_opts=LabelOpts(is_show=False))
# line.add_yaxis('美国疫情治愈人数', us_zy_y_data)
# line.add_yaxis('美国疫情死亡人数', us_sw_y_data)
# line.add_yaxis('美国疫情新增人数', us_xz_y_data)

line.set_global_opts(
    title_opts=TitleOpts(title='2020年美日印三国确诊人数对比折线图', pos_left='center', pos_bottom='1%'),
    toolbox_opts=ToolboxOpts(is_show=True),
    visualmap_opts=VisualMapOpts(is_show=True),
    legend_opts=LegendOpts(is_show=True)
)

line.render()
